package com.love.poetry.application.security.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.love.poetry.application.security.AuthorityService;
import com.love.poetry.domain.security.Authority;
import com.love.poetry.infrastructure.persist.security.AuthorityRepository;
import com.youboy.core.domain.event.LifecycleEvent;
import com.youboy.core.domain.event.LifecycleEventHandler;
import com.youboy.core.orm.Page;

@Transactional
@Service
public class AuthorityServiceImpl extends LifecycleEventHandler implements AuthorityService{

	@Autowired
    private AuthorityRepository authorityRepository ;


    public Authority get(String id) {
                return authorityRepository .get(id);
   }


    public List<Authority> query(Object object) {
                return authorityRepository .query(object);
   }


    public Page<Authority> queryPage(Page<Authority> page) {
                return authorityRepository .queryPage(page);
   }

    @Override
    protected void onModify(Object source, long timestamp) {
               Authority entity = (Authority) source;
                authorityRepository .update(entity);
   }

    @Override
    protected void onDelete(Object source, long timestamp) {
               Authority entity = (Authority) source;
                authorityRepository .delete(entity);

   }

    @Override
    protected void onCreate(Object source, long timestamp) {
               Authority entity = (Authority) source;
                authorityRepository .save(entity);

   }

    @Override
    protected boolean isAcceptableLifecycleEvent(LifecycleEvent event) {
                return Authority. class.isAssignableFrom( event.getSource().getClass());
   }

}
